/*
 * @Author: Turump 
 * @Date: 2021-05-11 20:10:04 
 * @Last Modified by: Turump
 * @Last Modified time: 2021-05-26 15:05:04
 */

import CocosHelper from "../../helper/CocosHelper";
import { TweenType } from "../../misc/TweenType";
import ActionBaseTask from "./ActionBaseTask";

const { ccclass, property, menu } = cc._decorator;

@ccclass
@menu("动作任务/MoveTo")
export default class MoveToTask extends ActionBaseTask {

    @property({ displayName: "目标节点", type: cc.Node })
    targetNode: cc.Node = null;

    @property({ displayName: "MoveTo参数", tooltip:"如果设置了目标节点,此参数用作为偏移量" })
    moveToParam: cc.Vec2 = cc.v2(0, 0);

    getAction() {
        let targetPosition = cc.v2(0);
        if(this.targetNode) {
            targetPosition = CocosHelper.getPositionForNewParent(this.targetNode, this.node.parent);
        }
        return cc.tween(this.node)
            .then(this.getPlayAudioTween())
            .to(this.actionDuration, { position: cc.v3(targetPosition.add(this.moveToParam)) }, { easing: Object.keys(TweenType)[this.easeType] })
    }
}
